
cc.Class({
    extends: cc.Component,

    properties: {
        phoneEdit: cc.EditBox,
        pwdEdit: cc.EditBox,
        userEdit: cc.EditBox,
    },

    // onLoad () {},

    start () {

    },

    onBtnClk: function (event, param) {
        Global.AudioManager.playCommonSoundClickButton();
        switch (param) {
            case 'zhuce':
                let account = this.phoneEdit.string;
                let pwd = this.pwdEdit.string;
                let user = this.userEdit.string;
                if (account === '') {
                    Global.DialogManager.addTipDialog('请输入手机号！');
                    return;
                }

                if (account.length < 11 ) {
                    Global.DialogManager.addTipDialog('请输入正确的手机号！');
                    return;
                }

                if (!this.isValidChinesePhoneNumber(account)) {
                    Global.DialogManager.addTipDialog('请输入正确的手机号！');
                    return;
                }

                if (pwd === '') {
                    Global.DialogManager.addTipDialog('请输入密码！');
                    return;
                }
                
                let accountData = {
                    account: account,
                    password: pwd,
                    loginPlatform: Global.Enum.loginPlatform.MOBILE_PHONE
                };

                Global.DialogManager.addLoadingCircle();
                Global.LoginHelper.register(accountData, null, function () {
                    cc.sys.localStorage.setItem("accountDataArr", JSON.stringify(accountData));
                    Global.DialogManager.removeLoadingCircle();
                    Global.DialogManager.createDialog("UI/Hall/HallDialog", {lastDialog: "login"}, function () {
                        Global.DialogManager.destroyAllDialog(["UI/Hall/HallDialog"]);
                    })
                });
                break;
            case 'close':
                Global.DialogManager.destroyDialog(this);
                break;
        }
    },

    
    isValidChinesePhoneNumber: function(phoneNumber) {
        const regex = /^1[3-9]\d{9}$/;
        return regex.test(phoneNumber);
    }

    // update (dt) {},
});
